﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ClassLibrary.Data;
using System.Data;
using ClassLibrary.Entity;

namespace ClassLibrary.DAO
{
    public class DVKhachhangDAO
    {
        private DBService _db = null;
        public DVKhachhangDAO(String ConnectionString)
        {
            _db = new DBService(ConnectionString);
        }

        public DataTable InsDVKH(DVKhachhang dvkh, int mode)
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("sp_DVKhachhang_InsUp",
                    new string[] { "@IDDVKH", "@TieuDe", "@NoiDung", "@ImageURL", "@Mode" }, 
                    new object[] { dvkh.IDDVKH, dvkh.TieuDe, dvkh.NoiDung, dvkh.ImageURL, mode }, CommandType.StoredProcedure);

            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable GetDVKH_All()
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("select * from DVKhachhang", false, CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable GetDVKH_Top()
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("select top(1) * from DVKhachhang order by IDDVKH DESC", false, CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        public DataTable GetDVKH_ByID(int IDDVKH)
        {
            DataTable dt = null;
            try
            {
                dt = _db.ExeSP_DataTable("select * from DVKhachhang where IDDVKH = @IDDVKH", 
                    new string[]{ "@IDDVKH" }, new object[]{ IDDVKH }, CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dt;
        }

        // delete dvkh
        public bool DeleteItem(int IDDVKH)
        {
            bool flag = false;
            try
            {
                _db.ExeSP_NonQuery("delete from DVKhachhang where IDDVKH = @IDDVKH",
                    new string[] { "@IDDVKH" },
                    new object[] { IDDVKH },
                    CommandType.Text);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return flag;
        }

    }
}
